package cyb.test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class test3 {
    public static void main(String[] args) {
        Map<String, String> poiMap = new HashMap<>();
        poiMap.put("11", "A");
        poiMap.put("12", "A");
        poiMap.put("21", "B");
        poiMap.put("31", "C");
        poiMap.put("41", "D");

        Set<String> dSet = new HashSet<>();
        dSet.add("41");
        Set<String> cSet = new HashSet<>();
        cSet.add("31");
        Set<String> bSet = new HashSet<>();
        bSet.add("21");
        Set<String> aSet = new HashSet<>();
        aSet.add("11");
        aSet.add("12");

        Map<String, Map<String, Set<String>>> neighborMap = new HashMap<>();

        Map<String, Set<String>> a1Nei = new HashMap<>();
        a1Nei.put("D", dSet);
        neighborMap.put("11", a1Nei);

        Map<String, Set<String>> a2Nei = new HashMap<>();
        a2Nei.put("D", dSet);
        neighborMap.put("12", a2Nei);

        Map<String, Set<String>> b1Nei = new HashMap<>();
        b1Nei.put("C", cSet);
        b1Nei.put("D", dSet);
        neighborMap.put("21", b1Nei);

        Map<String, Set<String>> c1Nei = new HashMap<>();
        c1Nei.put("B", bSet);
        c1Nei.put("D", dSet);
        neighborMap.put("31", c1Nei);

        Map<String, Set<String>> d1Nei = new HashMap<>();
        d1Nei.put("A", aSet);
        d1Nei.put("B", bSet);
        d1Nei.put("C", cSet);
        neighborMap.put("41", d1Nei);

        Map<String, Map<String, Set<String>>> graph = neighborMap;


        final int n = graph.size();
        final int[] corenesses = new int[n];
        final Set<String> S = graph.keySet();//S是未处理的点

        for (int k = 1; ; k++) {
            System.err.println("Progress:" + (n - S.size()) + "/" + n);

            if (S.isEmpty())
                break;
            Set<String> SDel = new HashSet<>();
            for (String instance : S) {
                if (graph.get(instance).size() < k) {
                    SDel.add(instance);
                }
            }
            while (!SDel.isEmpty()) {
                final Set<String> SDelNew = new HashSet<>();
                for (String instance : SDel) {
                    //删除每个不符合度数的实例后，要对设计的实例再删一次
//                    for (String j : graph.get(instance)) {
//                        upper[j]--;
//                        if (upper[j] == k - 1) {
//                            SDelNew.add(j);
//                        }
//                    }
//
//                    S.remove(i);
//                    corenesses[i] = k - 1;
                }
                SDel = SDelNew;
            }
        }

    }
}
